package com.edu.demo.controller;

import com.edu.demo.exception.CaptchaException;
import com.edu.demo.pojo.AjaxResult;
import com.edu.demo.pojo.LoginBody;
import com.edu.demo.service.impl.UserDetailServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: LoginController
 * @Description:
 * @Author: jxw
 * @Date: 2023-01-14
 */
@RestController
public class LoginController {


    @Qualifier("userDetailServiceImpl")
    @Autowired
    private UserDetailServiceImpl userDetailsService;

    /**
     * 管理员、教师、学生登录
     * @param loginBody
     * @return
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody){
        AjaxResult login = null;
        try {
            login = userDetailsService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), loginBody.getUuid(), loginBody.getLoginType());
        } catch (CaptchaException e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
        return login;
    }
}
